﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using DXApplicationTangche.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DXApplicationTangche.UC.订单一览新.客户充值
{
    public class 会员预存Service
    {
        public static List<RechargeBackDTO> getViewRechargeBackDTOAll()
        {
            return
                FunctionHelper.JsonDeserialization<List<RechargeBackDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/saleConfirm/getViewRechargeBackDTOAll"
                    )
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="memberRechargeRequestDTO"></param>
        /// <returns></returns>
        public static String saveMemberRecharge(MemberRechargeRequestDTO memberRechargeRequestDTO)
        {
            return
                RestCall.PostHttp(
                        URL.接口url + "/customer/saveMemberRecharge",
                        FunctionHelper.JsonSerialization(memberRechargeRequestDTO)
                        ) ;
        }

    }

    public class RechargeBackDTO
    {
        public String id { get; set; }
        public String mobile { get; set; }
        public String customerName { get; set; }
        public Double rechargeAmount { get; set; }
        public Double backAmount { get; set; }
        public Double actualAmount { get; set; }
        public String storeId { get; set; }
        public String storeName { get; set; }
        public String assistantId { get; set; }
        public String assistantName { get; set; }
        public DateTime createDate { get; set; }
        public RechargeBackDTO()
        {

        }
        public RechargeBackDTO(DataRow dataRow)
        {
            this.id = dataRow["id"].ToString();
            this.mobile = dataRow["mobile"].ToString();
            try { this.customerName = dataRow["customerName"].ToString(); } catch { }
            try { this.rechargeAmount = Convert.ToDouble(dataRow["rechargeAmount"].ToString()); } catch { }
            try { this.backAmount = Convert.ToDouble(dataRow["backAmount"].ToString()); } catch { }
            try { this.actualAmount = this.rechargeAmount - this.backAmount; } catch { }
            this.storeId = dataRow["storeId"].ToString();
            this.storeName = dataRow["storeName"].ToString();
            this.assistantId = dataRow["assistantId"].ToString();
            this.assistantName = dataRow["assistantName"].ToString();
            try { this.createDate = Convert.ToDateTime(dataRow["createDate"].ToString()); } catch { }
        }
        
    }
    public class MemberRechargeRequestDTO
    {
        public String mobile { get; set; }      //  客户电话
        public Double rechargeAmount { get; set; }   //  账户金额：名单金额的6倍
        public Double backAmount { get; set; }   //  免单金额
        public String storeId { get; set; }  //  店铺
        public String assistantId { get; set; }  //  销售负责人
        public MemberRechargeRequestDTO()
        {

        }
        /// <summary>
        /// 会员充值带免单金额
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="backAmount"></param>
        /// <param name="storeId"></param>
        /// <param name="assistantId"></param>
        public MemberRechargeRequestDTO(string mobile, String backAmount, string storeId,string assistantId)
        {
            this.mobile = mobile;
            if (!String.IsNullOrEmpty(backAmount))
            {
                try { this.backAmount = Convert.ToDouble(backAmount); } catch { this.backAmount = 0.0; }
                try { this.rechargeAmount = this.backAmount * 6; } catch { this.rechargeAmount = 0.0; }
            }
            this.storeId = storeId;
            this.assistantId = assistantId;
        }
        /// <summary>
        /// 会员充值无免单
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="backAmount"></param>
        /// <param name="rechargeAmount"></param>
        /// <param name="storeId"></param>
        /// <param name="assistantId"></param>
        public MemberRechargeRequestDTO(string mobile, Double backAmount,String rechargeAmount, string storeId, string assistantId)
        {
            this.mobile = mobile;
            this.backAmount = backAmount;
            if (!String.IsNullOrEmpty(rechargeAmount))
            {
                try { this.rechargeAmount = Convert.ToDouble(rechargeAmount); } catch { this.rechargeAmount = 0.0; }
            }
            this.storeId = storeId;
            this.assistantId = assistantId;
        }
    }
}
